xend: Avoid deprecation warnings with Python 2.6.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 19 May 2009 00:34:34 +0000 (01:34 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 19 May 2009 00:34:34 +0000 (01:34 +0100)
Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
tools/python/xen/util/acmpolicy.py
tools/python/xen/xend/XendAPI.py

index 1a95c3a2d5d77aa5f3ae6b84bb0ee987454be2f0..6752169c7b4273793887e64b02db047086645512 100644 (file)
 #============================================================================
 
 import os
-import sha
 import stat
 import array
 import struct
 import shutil
 import commands
+
+# sha is deprecated as of python 2.6
+try:
+    from hashlib import sha1
+except ImportError:
+    # but hashlib was only added in python 2.5
+    from sha import new as sha1
+
 from xml.dom import minidom, Node
 from xen.xend.XendLogging import log
 from xen.util import xsconstants, bootloader, mkdir
@@ -1102,8 +1109,8 @@ class ACMPolicy(XSPolicy):
         return None
 
     def hash(self):
-        """ Calculate a SAH1 hash of the XML policy """
-        return sha.sha(self.toxml())
+        """ Calculate a SHA1 hash of the XML policy """
+        return sha1(self.toxml())
 
     def save(self):
         ### Save the XML policy into a file ###
index 07e6b2100ecd7a41a1d0a0abfc2694bb3a6c13d5..6dda3a9c799bbe3849b1dea37ed865d59c64cbcc 100644 (file)
@@ -18,7 +18,6 @@
 import inspect
 import os
 import Queue
-import sets
 import string
 import sys
 import traceback
@@ -26,6 +25,12 @@ import threading
 import time
 import xmlrpclib
 
+# sets is deprecated as of python 2.6, but set is unavailable in 2.3
+try:
+    set
+except NameError:
+    from sets import Set as set
+
 import XendDomain, XendDomainInfo, XendNode, XendDmesg
 import XendLogging, XendTaskManager, XendAPIStore
 
@@ -119,16 +124,17 @@ event_registrations = {}
 def event_register(session, reg_classes):
     if session not in event_registrations:
         event_registrations[session] = {
-            'classes' : sets.Set(),
+            'classes' : set(),
             'queue'   : Queue.Queue(EVENT_QUEUE_LENGTH),
             'next-id' : 1
             }
     if not reg_classes:
         reg_classes = classes
-    if hasattr(set, 'union_update'):
-        event_registrations[session]['classes'].union_update(reg_classes)
+    sessionclasses = event_registrations[session]['classes']
+    if hasattr(sessionclasses, 'union_update'):
+        sessionclasses.union_update(reg_classes)
     else:
-        event_registrations[session]['classes'].update(reg_classes)
+        sessionclasses.update(reg_classes)